// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose:  Definition of CXFormsConfig class..
//   $Id$


#pragma once
#include "blowfish_ctx.h"

class CXFormsConfig
{
public:
	// Construction and destruction.
	CXFormsConfig();
	virtual ~CXFormsConfig();

	// Populate the current object with data from the supplied XML DOM.
	HRESULT Initialise(IXMLDOMDocument *pConfigDOM);
	
	// Populate the current object with magic data.
	HRESULT Initialise();

	// Set the current version of formsPlayer.
	inline void CurrentVersion(BSTR sVersion);

	// Methods to return values of class properties.
	bool FormBranding(void);
	bool ControlBranding(void);
	BSTR ControlBrandingLogo(void);
	bool FormBrandingDebugInfo(void);
	bool MessageBranding(void);
	BSTR MessageLogo(void);
	bool SplashPage(void);
	BSTR SplashPageURL(void);
	BSTR Version(void);
	bool ValidVersion(void);
	BSTR Date(void);
	bool ValidDate(void);
	bool Softbar(void);
	BSTR SoftbarName(void);
	bool SoftbarBranding(void);
	bool ShowDefaultSubmitError(void);
	inline bool Initialised(void) const;

private:
	// Process settings from any <link> elements that are children of pParentElement.
	HRESULT ProcessChildLinkElements(IXMLDOMElement *pParentElement);

	// Process settings from any <meta> elements that are children of pParentElement.
	HRESULT ProcessChildMetaElements(IXMLDOMElement *pParentElement);

	// Return the BSTR value of attribute sAttribute on XML element pElement.
	HRESULT GetAttribute(IXMLDOMElement *pElement, BSTR sAttribute, BSTR *psValue) const;

	// Return sString with occurrences of {$xxx} replaced by expanded environment variable.
	HRESULT ExpandEnvironmentVariables(CComBSTR &sString) const;

	// Set the specified property to the supplied value.
	HRESULT SetProperty(BSTR sProperty, BSTR sValue);
	HRESULT SetProperty(BSTR sProperty, bool bValue);

	// Configuration variables
	bool m_bShowFormBrand;
	bool m_bShowControlBrand;
	CComBSTR m_bsControlBrandLogo;
	bool m_bDisplayDebugInfo;
	bool m_bShowMessageBrand;
	CComBSTR m_bsMessageLogo;
	bool m_bShowSplashPage;
	CComBSTR m_bsSplashPage;
	CComBSTR m_bsCurrentVersion;
	CComBSTR m_bsVersion;
	bool m_bValidVersion;
	CComBSTR m_bsDate;
	bool m_bValidDate;
	CComBSTR m_bsSoftbar;
	bool m_bShowSoftbar;
	bool m_bBrandSoftbar;
	bool m_bShowDefaultSubmitError;

	// Initialisation flag.
	bool m_bInitialised;

};

// Set the current version of formsPlayer.
inline void CXFormsConfig::CurrentVersion(BSTR sVersion)
{
	m_bsCurrentVersion = sVersion;
}

// Return the value of the initialisation flag.
inline bool CXFormsConfig::Initialised(void) const
{
	return m_bInitialised;
}
